package com.neusoft.tyut.tyutcat.servlet.factory;

import com.neusoft.tyut.tyutcat.servlet.Servlet;
import com.neusoft.tyut.tyutcat.servlet.http.HttpServlet;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

public class ServletFactory {



    public  static Map<String,Servlet>   servletMap =new HashMap<>();

    public static Servlet getServlet(String name) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
//        login.do   --- > com.neusoft.tyut.tyutcat.servlet.http.HttpServlet
        Servlet servlet  =   servletMap.get(name);
       if  (Objects.isNull(servlet) ){
            switch (name){
                case    "login.do" :
                    name = "com.neusoft.tyut.tyutcat.servlet.http.HttpServlet";
            }
            Class  clazz =  Class.forName(name);
           servlet =   (Servlet) clazz.newInstance();
        }
        return    servlet;
    }
}
